# coding: utf-8
"""
@author: oldman
@file: 0103_str_join.py
@time: 2021-07-29
"""

"""
字符串转化：
AABBBACCCC->2A3B1A4C
"""


def str_conversion(s):
    if s is None or s == "":
        return None

    res_str = ""
    tmp_count = 1

    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            tmp_count += 1
        else:
            res_str += str(tmp_count)
            res_str += s[i - 1]
            tmp_count = 1
    res_str += str(tmp_count)
    res_str += s[-1]

    return res_str


print(str_conversion("AABBBACCCC"))
print(str_conversion("AABBBAABDFCCCC"))
